package com.topica.database.task;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;

import com.topica.database.DataBaseHelper;
import com.topica.database.callback.OnGetListCourseListener;
import com.topica.object.CourseItem;

public class GetListCourseTask extends TopicaDBTask {
	private static final String TAG = "GetListCourseTask";
	private ArrayList<CourseItem> items;
	private OnGetListCourseListener listener;

	public GetListCourseTask(Context context) {
		super(context);
	}

	@Override
	protected Integer doInBackground(Void... params) {
		DataBaseHelper myDbHelper = new DataBaseHelper(context.getApplicationContext());
		items = myDbHelper.getListCourse();
		myDbHelper.close();
		return OK;
	}

	@Override
	protected void onPostExecute(Integer result) {
		super.onPostExecute(result);
		if (result == OK) {
			listener.onGetListCourseListener(items);
		} else {
			Log.e(TAG, "Co loi khi lay danh sach course");
		}
	}

	public void setOnGetListCourseListener(OnGetListCourseListener listener) {
		this.listener = listener;
	}
}
